package com.bstek.config;

import java.util.Set;

import javax.security.auth.login.AccountExpiredException;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.LockedAccountException;
import org.apache.shiro.authc.SimpleAuthenticationInfo;
import org.apache.shiro.authc.UnknownAccountException;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.authz.SimpleAuthorizationInfo;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;
import org.apache.shiro.util.ByteSource;
import org.springframework.beans.factory.annotation.Autowired;


public class UserRealm extends AuthorizingRealm {

/*	@Autowired
	BaseUserService baseUserService;
	
	@Autowired
	FrameworkService frameworkService;*/
	
	@Override
	protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
			/*BaseUser user = (BaseUser) SecurityUtils.getSubject().getPrincipal();
			String username = user.getUsername();
			Set<String> permissions = frameworkService.listPerms(username);
			SimpleAuthorizationInfo authorizationInfo = new SimpleAuthorizationInfo();
	        authorizationInfo.setStringPermissions(permissions);
	        authorizationInfo.addStringPermissions(permissions);
	        return authorizationInfo;*/
			return null;
	}


	@Override
	protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException{
		/*String username = (String) token.getPrincipal();
		BaseUser user = baseUserService.findUserByUsername(username);
		if (user == null) {
			throw new UnknownAccountException();// 没找到帐号
		}
		if (Boolean.FALSE.equals(user.getAccountNonLocked())) {
			throw new LockedAccountException(); // 帐号锁定
		}
		if (Boolean.FALSE.equals(user.getAccountNonExpired())) {
			try {
				throw new AccountExpiredException();// 账号已过期
			} catch (AccountExpiredException e) {
				e.printStackTrace();
			}
		}
		SimpleAuthenticationInfo authenticationInfo2 = new SimpleAuthenticationInfo(user, user.getPassword(),
				ByteSource.Util.bytes(user.getCredentialsSalt()), getName());*/
		return null;
	}

}
